FROM ubuntu:ustc
SHELL ["/bin/bash", "-c"]

ARG UNAME=share
ARG UID=5002
ARG SAMB_PWD=share123456

RUN mkdir -p /srv/samba; \
groupadd ${UNAME} -g ${UID}; \
useradd -u ${UID} -g ${UID} ${UNAME} -d /srv/samba -s /sbin/nologin; \
chown ${UNAME}:${UNAME} /srv/samba; \
chmod 0775 /srv/samba; \
apt-get install -y samba samba-dsdb-modules smbclient cifs-utils dos2unix; \
apt-get clean ; apt-get autoclean ; apt-get autoremove ; rm -rf /var/lib/apt/lists/* ; 

COPY smb.conf /etc/samba/smb.conf
COPY entrypoint.sh /entrypoint.sh

USER root

RUN dos2unix /entrypoint.sh; chmod +x /entrypoint.sh; \
smbpasswd -x ${UNAME} || echo "" ; \
echo -e "${SAMB_PWD}\n${SAMB_PWD}" | smbpasswd -a -s ${UNAME}

VOLUME /srv/samba
EXPOSE 445
EXPOSE 139

ENTRYPOINT ["/entrypoint.sh"]
